package com.maistars.spider.service.render.impl;

import com.maistars.spider.service.domain.render.PageRequest;
import com.maistars.spider.service.domain.render.PageResponse;
import com.maistars.spider.service.render.PageRender;
import com.maistars.spider.service.render.handler.HtmlHandler;

/**
 * @author dhr
 * @date 2022/3/20 11:16 上午
 */
public abstract class AbstractPageRender implements PageRender {

    protected void handleHtml(PageRequest pageRequest, PageResponse pageResponse, String html) {
        HtmlHandler htmlHandler = pageRequest.getRenderConfig().getHtmlHandler();
        if (htmlHandler != null) {
            htmlHandler.getContext().put("orignalHtml", html);
            htmlHandler.getContext().put("orignalUrl", pageRequest.getUrl());
            htmlHandler.getContext().put("handledHtml", html);
            htmlHandler.getContext().put("removeElementSelectorList", pageRequest.getRenderConfig().getExtraParams().get("removeElementSelectorList"));
            htmlHandler.handle();
            pageResponse.setRenderResult(htmlHandler.getContext().get("handledHtml"));
        }
    }

}
